* This file constructs variables neededed for the analysis

sort id year
order id year, first

* Exit and Entry
sort id year
gen Entry = 0
gen Exit = 0
replace Entry = 1 if id[_n] != id[_n-1] & year[_n] > 1990
replace Exit = 1 if id[_n] != id[_n+1] & year[_n] < 2000

* Set Entry and Exit to missing in 1990 and 2000
mvdecode Entry if year == 1990, mv(0 = .)
mvdecode Exit if year == 2000, mv(0 = .)

// Sales growth year by year
sort id year
gen salesgrowth = .
replace salesgrowth = sales[_n]/sales[_n-1]-1 if id[_n] == id[_n-1]
label var salesgrowth "Growth of sales from last year sales_t/sales_t-1 - 1"

// Materials growth year by year
gen materialsgrowth = .
replace materialsgrowth = materials[_n]/materials[_n-1]-1 if id[_n] == id[_n-1]
label var materialsgrowth "Growth of materials from last year materials_t/materials_t-1 - 1"

// Total inputs:
gen inputs = materials + wages
gen inputgrowth = .
replace inputgrowth = inputs[_n]/inputs[_n-1]-1 if id[_n] == id[_n-1]
label var inputgrowth "Growth of inputs from last year materials_t/materials_t-1 - 1"
